/*****************************************************************************
	SNEGA UTILITIES 0.7a
	Copyright (C) 2009, Xiaohan Tian (snega0223)
	
	http://code.google.com/p/snega-utilities/
	
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License(LGPL) as
	published by the Free Software Foundation, either version 3 of the 
	License, or(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

package org.sng.util.var;

import java.util.*;

import org.sng.util.web.elmt.*;

public class SObject extends SVoid {
	
	protected HashMap<String, SVoid> m_map;
	protected SVoid [] m_array;
	
	public SObject()
	{
		this.m_map = new HashMap<String, SVoid>();
		this.m_array = null;
	}
	
	public SObject(int length)
	{
		this.m_map = new HashMap<String, SVoid>();
		this.m_array = new SVoid[length];
	}
	
	public int GetType()
	{
		return SType.OBJECT;
	}
	
	/* Hash Map */
	public void SetMember(RuntimeEnvironment in, String key, SVoid o)
	{
		this.m_map.put(key, o);
	}
	
	public void PushVar(String id, SVoid o)
	{
		this.m_map.put(id, o);
	}
	
	public void PushVar(String id, int i)
	{
		this.m_map.put(id, new SInt(i));
	}
	
	public void PushVar(String id, String s)
	{
		this.m_map.put(id, new SString(s));
	}
	
	public void PushVar(String id, StringBuffer s)
	{
		this.m_map.put(id, new SString(s));
	}
	
	public int GetLength()
	{
		return this.m_array.length;
	}
	
	public SVoid GetMember(RuntimeEnvironment in, String key)
	{
		return this.m_map.get(key);
	}
	
	/* Array */
	public SVoid [] GetArray(RuntimeEnvironment in)
	{
		return this.m_array;
	}
	
	public void PushVar(int i, SVoid o)
	{
		this.m_array[i] = o;
	}
	
	public void PushVar(int i, int j)
	{
		this.m_array[i] = new SInt(j);
	}
	
	public void PushVar(int i, String s)
	{
		this.m_array[i] = new SString(s);
	}
	
	public void PushVar(int i, StringBuffer s)
	{
		this.m_array[i] = new SString(s);
	}
	
	public void SetMember(RuntimeEnvironment in, int i, SVoid o)
	{
		this.m_array[i] = o;
	}
	
	public SVoid GetMember(RuntimeEnvironment in, int i)
	{
		return this.m_array[i];
	}
	
	/* Mix fetch */
	public SVoid GetMember(RuntimeEnvironment in, SVoid idx)
	{
		return null;
	}

}
